package com.isoft.result;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 封装分页查询结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "分页查询结果")
public class PageResult<T> {
    @Schema(description = "总记录数")
    private Long total;

    @Schema(description = "总页数")
    private Integer pages;

    @Schema(description = "当前页码")
    private Integer currentPage;

    @Schema(description = "每页记录数")
    private Integer pageSize;

    @Schema(description = "当前页数据集合")
    private List<T> records;

    // 添加构造方法
    public PageResult(PageInfo<?> pageInfo, List<T> list) {
        this.total = pageInfo.getTotal();
        this.pages = pageInfo.getPages();
        this.currentPage = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.records = list;
    }
}
